﻿using System.Linq;
using Hourglass.Qrobot.Http;
using Hourglass.Qrobot.Models;

namespace Hourglass.Qrobot
{
    public class SmartQQ
    {
        /// <summary>
        /// 登录用户的信息
        /// </summary>
        public UserInfo UserInfo { get; set; }

        /// <summary>
        /// 好友管理
        /// </summary>
        public FriendsManager FriendManager { get; set; }

        /// <summary>
        /// QQ群组管理
        /// </summary>
        public GroupsManager GroupManager { get; set; }

        /// <summary>
        /// 讨论组管理
        /// </summary>
        public DisscussesManager DisscussManager { get; set; }

        #region Contains

        public bool ContainsFriend(long id)
        {
            return FriendManager.Friends.ContainsKey(id);
        }

        public bool ContainsGroup(long groupCode)
        {
            return GroupManager.Groups.ContainsKey(groupCode);
        }

        public bool ContainsDisscuss(long disscussId)
        {
            return DisscussManager.Disscusses.ContainsKey(disscussId);
        }

        #endregion Contains

        #region Find

        public Friend FindFriendById(long id)
        {
            return this.FriendManager.FindFriendById(id);
        }

        public Friend FindFriendByQq(long qq)
        {
            return this.FriendManager.FindFriendByQq(qq);
        }

        public Group FindGroupByNumber(long number)
        {
            return this.GroupManager.FindGroupByNumber(number);
        }

        public Disscuss FindDisscussByName(string name)
        {
            return this.DisscussManager.FindDisscussByName(name);
        }

        public GroupMember FindMemberFromGroupByName(string markName, long groupCode)
        {
            return this.GroupManager.FindMemberByName(markName, groupCode);
        }

        public GroupMember FindMemberFromGroupById(long id, long groupCode)
        {
            return this.GroupManager.FindMemberById(id, groupCode);
        }

        public GroupMember FindMemberFromGroupByQq(long id, long groupCode)
        {
            return this.GroupManager.FindMemberByQq(id, groupCode);
        }

        public DisscussMember FindMemberFromDisscussByName(string nickName, long disscussId)
        {
            return this.DisscussManager.FindMemberFromDisscussByName(nickName, disscussId);
        }

        public DisscussMember FindMemberFromDisscussById(long id, long disscussId)
        {
            return this.DisscussManager.FindMemberFromDisscussById(id, disscussId);
        }

        public DisscussMember FindMemberFromDisscussByQq(long qq, long disscussId)
        {
            return this.DisscussManager.FindMemberFromDisscussByQq(qq, disscussId);
        }

        #endregion Find

        #region Add

        public void AddFrind(Friend friend)
        {
            this.FriendManager.Friends.Add(friend.Id, friend);
        }

        public void AddGroup(Group group)
        {
            this.GroupManager.Groups.Add(group.Id, group);
        }

        public void AddDisscuss(Disscuss disscuss)
        {
            this.DisscussManager.Disscusses.Add(disscuss.Id, disscuss);
        }

        #endregion Add

        public static bool IsAtAll(string name)
        {
            return name.Equals("all") || name.Equals("全体成员");
        }
    }
}
